﻿<Page
    x:Class="SharPy.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SharPy"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Page.Resources>
        <ResourceDictionary>
            <ResourceDictionary.ThemeDictionaries>
                <ResourceDictionary x:Key="Default">
                    <ImageBrush x:Key="HubBackgroundImageBrush" ImageSource="Assets/HubBackground.png"/>
                </ResourceDictionary>
                <ResourceDictionary x:Key="HighContrast">
                    <ImageBrush x:Key="HubBackgroundImageBrush" ImageSource="{x:Null}"/>
                </ResourceDictionary>
            </ResourceDictionary.ThemeDictionaries>
            
            <DataTemplate x:Key="HubSectionHeaderTemplate">
                <TextBlock Margin="0,0,0,-9.5" Text="{Binding}"/>
            </DataTemplate>

            <!-- Grid-appropriate item template as seen in section 2 -->
            <DataTemplate x:Key="StandardDoubleLineItemTemplate">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <Border Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" Margin="0,9.5,0,0" Grid.Column="0" HorizontalAlignment="Left">
                        <Image Source="{Binding ImagePath}" Stretch="UniformToFill" AutomationProperties.Name="{Binding Title}" Height="79" Width="79"/>
                    </Border>
                    <StackPanel Grid.Column="1" Margin="14.5,0,0,0">
                        <TextBlock Text="{Binding Title}" Style="{ThemeResource ListViewItemTextBlockStyle}">
                        </TextBlock>
                        <TextBlock Text="{Binding Subtitle}" Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}"/>
                    </StackPanel>
                </Grid>
            </DataTemplate>
        </ResourceDictionary>
    </Page.Resources>

    <Grid x:Name="LayoutRoot">
        <Hub x:Name="Hub" x:Uid="Hub" Header="{Binding Title}" Background="{ThemeResource HubBackgroundImageBrush}">
            <HubSection x:Uid="HubSection1" Header="Where am I?" DataContext="{Binding Groups}" HeaderTemplate="{ThemeResource HubSectionHeaderTemplate}">
                <DataTemplate>
                    <ScrollViewer VerticalScrollBarVisibility="Visible">
                        <StackPanel Orientation="Vertical">
                            <TextBlock TextWrapping="WrapWholeWords" HorizontalAlignment="Left" FontSize="17">
                            Welcome to functionality demo of SharPy Visual Novel engine! 
                            Thanks for your interest!
                            <LineBreak></LineBreak>
                            <LineBreak></LineBreak>
                            To start, click "refresh" button below, list of available games will
                            be downloaded and will appear in the hub section right of this one.
                            <LineBreak></LineBreak>
                            <LineBreak></LineBreak>
                            To start a game, click on its tile and select "Download/Play" option.
                            Watch the log section to see download progress and possible errors.
                            <LineBreak></LineBreak>
                            <LineBreak></LineBreak>  
                            Please see credits hubsection to find contacts and send your suggestions or bug reports!
                            =^_^=
                            </TextBlock>
                            <Button Name="Refresh"  Content="Refresh game list" Click="Refresh_Click"></Button>
                        
                        </StackPanel>
                    </ScrollViewer>
                </DataTemplate>
            </HubSection>

            <HubSection x:Uid="HubSection2" Header="Available games"
                        DataContext="{Binding gameItems}" HeaderTemplate="{ThemeResource HubSectionHeaderTemplate}">
                <DataTemplate>
                    <ListView 
                        AutomationProperties.AutomationId="ItemListViewSection5"
                        AutomationProperties.Name="Items In Group"
                        IsItemClickEnabled="True"
                        SelectionMode="Extended"
                        ItemsSource="{Binding Items}"
                        ItemTemplate="{StaticResource StandardDoubleLineItemTemplate}"
                        ItemClick="ItemView_ItemClick"
                        ContinuumNavigationTransitionInfo.ExitElementContainer="True"
                        >
                        <FlyoutBase.AttachedFlyout>
                            <Flyout>
                                <StackPanel Orientation="Vertical" >
                                    <TextBlock Text="{Binding SelectedGame}"></TextBlock>
                                    <Button Name="Download" Content="Download/Play" Click="Download_Click" Width="160"></Button>
                                    <Button Name="Restart" Content="Restart" Click="Restart_Click" Width="160"></Button>
                                    <Button Name="Delete" Content="Delete" Click="Delete_Click" Width="160"></Button>
                                </StackPanel>
                            </Flyout>
                        </FlyoutBase.AttachedFlyout>
                    </ListView>
                </DataTemplate>
            </HubSection>
            
            <HubSection x:Uid="HubSection3" Header="Log"
                HeaderTemplate="{ThemeResource HubSectionHeaderTemplate}">
                <DataTemplate>
                    <ScrollViewer>
                        <TextBlock Name="Log" Text="{Binding Log}"></TextBlock>
                    </ScrollViewer>
                </DataTemplate>
            </HubSection>
            
            <HubSection x:Uid="HubSection3" Header="Credits"
                HeaderTemplate="{ThemeResource HubSectionHeaderTemplate}">
                <DataTemplate>
                    <StackPanel>
                        <TextBlock FontSize="18" TextWrapping="WrapWholeWords">
                        SharPy is a visual novel engine inspired by RenPy. Please visit their site and support.
                        </TextBlock>
                        <HyperlinkButton FontSize="19" Foreground="Cyan" NavigateUri="http://www.renpy.org">
                            www.renpy.org
                        </HyperlinkButton>
                        <TextBlock FontSize="18" TextWrapping="WrapWholeWords">
                            SharPy VN is completely free and open-source. Visit codeplex page to find source code:
                        </TextBlock>
                        <HyperlinkButton FontSize="19" Foreground="Cyan" NavigateUri="http://www.sharpyvn.codeplex.com">
                            www.sharpyvn.codeplex.net
                        </HyperlinkButton>
                        <TextBlock FontSize="18" TextWrapping="WrapWholeWords">
                        If you are interested in developing games,
                        porting your RenPy game or developing the engine
                        itself, please e-mail me at
                        </TextBlock>
                        <HyperlinkButton FontSize="19"  Foreground="Cyan" NavigateUri="mailto:boris@2ch.hk">
                            boris@2ch.hk
                        </HyperlinkButton>
                        <TextBlock FontSize="18">
                              or  
                        </TextBlock>
                        <HyperlinkButton  FontSize="19"  Foreground="Cyan" NavigateUri="mailto:sharpyvn@outlook.com">
                            sharpyvn@outlook.com
                        </HyperlinkButton>
                    </StackPanel>
                </DataTemplate>
            </HubSection>
        </Hub>
    </Grid>


</Page>
